#pragma once
#include "hash.hpp"

namespace lw
{
	template<class K, class T, class Hash = HashFunc<K>, class Equal = std::equal_to<K>>
	class unordered_map
	{
		struct MapKeyOfT
		{
			const K& operator()(const std::pair<K, T>& kv) const
			{
				return kv.first;
			}
		};
	public:
		typedef typename lw::HashBucket<K, std::pair<const K, T>, MapKeyOfT, Hash, Equal>::iterator iterator;
		typedef typename lw::HashBucket<K, std::pair<const K, T>, MapKeyOfT, Hash, Equal>::const_iterator const_iterator;
		iterator begin() 
		{
			return _hash.begin();
		}
		iterator end() 
		{
			return _hash.end();
		}
		const_iterator begin() const
		{
			return _hash.begin();
		}
		const_iterator end() const
		{
			return _hash.end();
		}
		size_t size() const
		{
			return _hash.size();
		}
		T& operator[](const K& key)
		{
			std::pair<iterator, bool> p = _hash.Insert(std::make_pair(key, T()));
			return p.first->second;
		}
		std::pair<iterator, bool> insert(const std::pair<K, T>& kv)
		{
			return _hash.Insert(kv);
		}
		size_t erase(const K& key)
		{
			return _hash.Erase(key);
		}
		iterator find(const K& key)
		{
			return _hash.Find(key);
		}
		size_t bucket_count() const
		{
			return _hash.bucket_count();
		}
		size_t bucket(const K& key) const
		{
			return _hash.bucket(key);
		}

	private:
		lw::HashBucket<K, std::pair<const K, T>, MapKeyOfT, Hash, Equal> _hash;
	};
}